package com.zp.business.controller.outpFees;

import com.zp.business.entity.outpFees.bo.OutpFeesDetailBo;
import com.zp.business.entity.outpFees.vo.OutpFeesDetailVo;
import com.zp.business.service.outpFees.IOutpFeesDetailService;
import com.zp.common.core.controller.BaseController;
import com.zp.common.core.entity.R;
import com.zp.common.core.validate.AddGroup;
import com.zp.common.core.validate.EditGroup;
import com.zp.common.excel.utils.ExcelUtil;
import com.zp.common.log.annotation.Log;
import com.zp.common.log.enums.BusinessType;
import com.zp.common.myBatis.core.page.PageQuery;
import com.zp.common.myBatis.core.page.TableDataInfo;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Arrays;
import java.util.List;

/**
 * 门诊收费记录明细控制器
 * 前端访问路由地址为:/finance/outpFeesDetail
 *
 * @author zhang peng
 * @ date 2024-04-12
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/outpFeesDetail")
public class OutpFeesDetailController extends BaseController {

    private final IOutpFeesDetailService iOutpFeesDetailService;

    /**
     * 查询门诊收费记录明细列表 (分页)
     */
//    @SaCheckPermission("finance:outpFeesDetail:list")
    @GetMapping("/selectPage")
    public TableDataInfo<OutpFeesDetailVo> selectPage (OutpFeesDetailBo bo, PageQuery pageQuery) {
        return iOutpFeesDetailService.queryPageList(bo, pageQuery);
    }

    /**
     * 查询门诊收费记录明细列表 (不分页)
     */
//    @SaCheckPermission("finance:outpFeesDetail:list")
    @GetMapping("/list")
    public R<List<OutpFeesDetailVo>> list (OutpFeesDetailBo bo) {
        List<OutpFeesDetailVo> list = iOutpFeesDetailService.queryList(bo);
        return R.ok(list);
    }

    /**
     * 导出门诊收费记录明细列表
     */
//    @SaCheckPermission("finance:outpFeesDetail:export")
    @Log(title = "门诊收费记录明细", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export (OutpFeesDetailBo bo, HttpServletResponse response) {
        List<OutpFeesDetailVo> list = iOutpFeesDetailService.queryList(bo);
        ExcelUtil.exportExcel(list, "门诊收费记录明细", OutpFeesDetailVo.class, response);
    }

    /**
     * 获取门诊收费记录明细详细信息
     *
     * @param outpFeesDetailId 主键
     */
//    @SaCheckPermission("finance:outpFeesDetail:list")
    @GetMapping("/{outpFeesDetailId}")
    public R<OutpFeesDetailVo> getInfo (@NotNull(message = "主键不能为空") @PathVariable String outpFeesDetailId) {
        return R.ok(iOutpFeesDetailService.queryById(outpFeesDetailId));
    }

    /**
     * 新增门诊收费记录明细
     */
//    @SaCheckPermission("finance:outpFeesDetail:add")
    @Log(title = "门诊收费记录明细", businessType = BusinessType.INSERT)
    @PostMapping()
    public R<Void> add (@Validated(AddGroup.class) @RequestBody OutpFeesDetailBo bo) {
        return toAjax(iOutpFeesDetailService.insertByBo(bo) ? 1 : 0);
    }

    /**
     * 修改门诊收费记录明细
     */
//    @SaCheckPermission("finance:outpFeesDetail:edit")
    @Log(title = "门诊收费记录明细", businessType = BusinessType.UPDATE)
    @PutMapping()
    public R<Void> edit (@Validated(EditGroup.class) @RequestBody OutpFeesDetailBo bo) {
        return toAjax(iOutpFeesDetailService.updateByBo(bo) ? 1 : 0);
    }

    /**
     * 删除门诊收费记录明细
     *
     * @param outpFeesDetailIds 主键串
     */
//    @SaCheckPermission("finance:outpFeesDetail:remove")
    @Log(title = "门诊收费记录明细", businessType = BusinessType.DELETE)
    @DeleteMapping("/{outpFeesDetailIds}")
    public R<Void> remove (@NotEmpty(message = "主键不能为空") @PathVariable String[] outpFeesDetailIds) {
        return toAjax(iOutpFeesDetailService.deleteWithValidByIds(Arrays.asList(outpFeesDetailIds), true) ? 1 : 0);
    }
}
